<!DOCTYPE html>
<html lang='zh-CN'>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
  <title>会员管理</title>
  <link href="css/bootstrap.min.css" rel="stylesheet">
  <link href="css/materialdesignicons.min.css" rel="stylesheet">
  <link href="css/animate.css" rel="stylesheet">
  <link href="css/style.min.css" rel="stylesheet">
  <link href="js/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
</head>
<body>
<div class="container-fluid p-t-15">
  <div class="row">
    <div class="col-lg-12">
      <div class="card">
        <div class="card-header">
          <div id="toolbar" class="toolbar-btn-action">
            <form class="form-inline" method="post" id="searchForm">
              <div class="form-group">
                <label>会员账号:</label>
                <input type="text" class="form-control" name="memberAccount">
                <label>会员昵称:</label>
                <input type="text" class="form-control" name="nickName">
                <label>手机号码:</label>
                <input type="text" class="form-control" name="memberPhone">
                <label>注册时间:</label>
                <input type="text" class="form-control js-datepicker" data-date-format="yyyy-mm-dd" name="registerTime" placeholder="开始时间">
              </div>
              <div class="form-group">
                <button class="btn btn-info btn_query btn-round" type="button" id="searchFormBtn">查询</button>
              </div>
            </form>
          </div>
        </div>
        <div class="card-body">
          <table id="grid_data" class="table text-nowrap"></table>
        </div>
      </div>
    </div>
  </div>
</div>

<!-- 赠送优惠券 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">赠送优惠券</h4>
      </div>
      <div class="modal-body">
        <form class="form-inline" method="post" id="searchCouponForm">
        </form>
        <div class="tab-content p-10">
          <table id="coupon_data" class="table text-nowrap"></table>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button type="button" class="btn btn-primary" id="couponBtn">确定</button>
      </div>
    </div>
  </div>
</div>
<#include "/footer.html"/>
<!--日期选择插件-->
<script src="js/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
<script src="js/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
<script src="js/main.min.js"></script>
<script type="text/javascript">

  //设置表头
  var columnes = [
    {checkbox: true},
    {field: 'id',title: '编号'},
    {field: 'couponName',title: '优惠劵名称'},
    {field: 'couponType', title: '优惠劵类型',formatter: function (value, row){
        if (value==1){ return "满减券"
        }else if (value==2){ return "商品卷"
        }else if (value==3){ return "赠送卷"
        }else if (value==4){ return "新人劵"
        }else if (value==5){ return "通用券" }}},
    {field: 'faceValue',title: '优惠劵面值'},
    {field: 'faceValueDemand',title: '面值条件'},
    {field: 'startTime',title: '开始时间',formatter: function (value) { return zero2one.dateFormat(value, 'Y-m-d H:i:s') }},
    {field: 'endTime',title: '结束时间',formatter: function (value) { return zero2one.dateFormat(value, 'Y-m-d H:i:s') }},
    {field: 'receiveType',title: '领取类型',formatter: function (value, row, index) {return value == 1 ? "手动领取": "自动领取";}},
    {field: 'ruleOrder',title: '规则排序'},
    {field: 'ruleStatus',title: '规则状态',formatter: function (value, row, index) {
        return value == 1 ? '<span class="label label-success">开启</span>':'<span class="label label-secondary">关闭</span>';}}
  ];

  zero2one.datagrids("coupon_data", "/remote/coupon/list",function (params) {
    return $.extend(zero2one.tableInitParam(params), zero2one.form2json("searchCouponForm"));
  }, columnes,function (data) {});

  //设置表头
  var columns = [
    {checkbox: true},
    {
      field: 'operate',
      title: '操作',
      formatter: function (event, value, row, index) {
          return '<a href="#!" class="btn btn-xs btn-primary m-r-5 reset-pwd-btn" title="重置登录密码" data-toggle="tooltip"><i class="mdi mdi-lock-reset"></i></a>' +
                  '<a href="#!" class="btn btn-xs btn-info m-r-5 reset-payPwd-btn" title="重置支付密码" data-toggle="tooltip"><i class="mdi mdi-lock-reset"></i></a>' +
                  '<a href="#!" class="btn btn-xs btn-danger m-r-5 disabled-btn" title="禁用用户" data-toggle="tooltip"><i class="mdi mdi-lock"></i></a>' +
                  '<a href="#!" class="btn btn-xs btn-primary m-r-5 active-btn" title="撤销禁用" data-toggle="tooltip"><i class="mdi mdi-lock-open"></i></a>' +
                  '<a href="#!" class="btn btn-xs btn-yellow m-r-5 give-btn" title="赠送优惠券" data-toggle="tooltip"><i class="mdi mdi-plus-box"></i></a>' +
                  '<a href="#!" class="btn btn-xs btn-purple m-r-5 watch-btn" title="查看我的粉丝" data-toggle="tooltip"><i class="mdi mdi-magnify"></i></a>' +
                  '<a href="#!" class="btn btn-xs btn-cyan m-r-5 watch-btn" title="查看消费记录" data-toggle="tooltip"><i class="mdi mdi-magnify"></i></a>' +
                  '<a href="#!" class="btn btn-xs btn-pink watch-coupon-btn" title="查看优惠券" data-toggle="tooltip"><i class="mdi mdi-magnify"></i></a>';
      },  // 自定义方法
      events: {
        'click .reset-pwd-btn': function (event, value, row, index) {
          resetPwd(row, 1);
        },
        'click .reset-payPwd-btn': function (event, value, row, index) {
          resetPwd(row, 2);
        },
        'click .disabled-btn': function (event, value, row, index) {
          editStatus(row, 0);
        },
        'click .active-btn': function (event, value, row, index) {
          editStatus(row, 1);
        },
        'click .give-btn': function (event, value, row, index) {
          giveCoupon(row);
        },
        'click .watch-coupon-btn': function (event, value, row, index) {
          watchCoupon(row);
        }
      }
    },
    {field: 'memberId',title: '会员ID'},
    {field: 'memberAccount',title: '会员账号'},
    {field: 'nickName',title: '会员昵称'},
    {field: 'sex',title: '会员性别',formatter: function (value, row, index) {return value == 1 ? "男": value == 2 ? "女": "保密";}},
    {field: 'memberGrade',title: '会员等级'},
    {field: 'memberPhone',title: '手机号码'},
    {field: 'statusId',align:'center',title: '会员状态', formatter: function(value) {
        return value == 1 ? '<span class="label label-success">正常</span>':'<span class="label label-danger">禁用</span>';
    }},
    {field: 'isUsed',align:'center',title: '新老会员', formatter: function(value) {
        return value == 1 ? '<span class="label label-purple">老会员</span>':'<span class="label label-success">新会员</span>';
    }},
    {field: 'registerTime',title: '注册时间',formatter: function (value) {
        return zero2one.dateFormat(value, 'Y-m-d H:i:s')}}
  ];

  //进入主界面加载数据
  zero2one.datagrids("grid_data", "/remote/member/list",function (params) {
    return $.extend(zero2one.tableInitParam(params), zero2one.form2json("searchForm"));
  }, columns,function (data) {});

  //点击查询按钮重新加载页面数据
  $("#searchFormBtn").click(function () {
    $('#grid_data').bootstrapTable('refresh');
  });

  //重置登录密码
  function resetPwd(row, type) {
    var title = type == 1 ? "您确定要重置登录密码吗？" : "您确定要重置支付密码吗？";
    $.messager.confirm("温馨提示", title, function () {
      zero2one.request("/remote/member/resetPwd",{memberId : row.memberId, type: type},function (data) {
        window.location.reload();
      });
    })
  }

  //禁用/撤销禁用
  function editStatus(row, type) {
    var title = type == 0 ? "您确定要禁用会员吗？" : "您确定要撤销禁用吗？";
    $.messager.confirm("温馨提示", title, function () {
      zero2one.request("/remote/member/status",{memberId : row.memberId, type: type},function (data) {
        window.location.reload();
      });
    })
  }

  //赠送优惠券
  function giveCoupon(row) {
    var datas = $("#grid_data").bootstrapTable('getSelections');
    if(datas.length >= 1){
      $("#myModal").modal("show");
    }else {
      $.messager.alert("温馨提示", "请选择一个或多个进行赠送优惠券");
    }
  }
  $("#couponBtn").click(function () {
    var datas = $("#grid_data").bootstrapTable('getSelections');
    var dataes = $("#coupon_data").bootstrapTable('getSelections');
    if(dataes.length == 1){
      zero2one.request("/remote/member/coupon",{memberIds : zero2one.dynamicArray2str(datas, "memberId"), couponId: zero2one.dynamicArray2str(dataes, "id")},function (data) {
        window.location.reload();
      });
    }else {
      $.messager.alert("温馨提示", "请选择一条规则操作");
    }
  });

  //查看会员优惠券
  function watchCoupon(row) {
      zero2one.tab("查看会员优惠券","/toView?url=service/member/memberCoupon&memberId="+row.memberId,120);
  }

</script>
</body>
</html>
